﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using LPY.LeHealth.DTO;

namespace LPY.LeHealth.DAL
{
    using ServiceStack.OrmLite;
    public  class TuanOrderDal:BaseDAL
    {
        /// <summary>
        /// 分页显示团检表信息
        /// </summary>
        /// <param name="num"></param>
        /// <returns></returns>
        public List<TuanOrderDTO> GetTuanOrder(int num,int hid)
        { 
            using(var cnn=DbConnection)
            {
                var sql = cnn.From<TuanOrderDTO>()
                    .Where(m=>m.HospitalId==hid)
                    .OrderByDescending(m => m.Tdate).Take(num);
                
                var rtv = cnn.Select(sql).ToList();
                return rtv;
            }
        }

        /// <summary>
        /// 根据Id修改团检订单状态
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public bool UpdTuanOrderById(int id,int state)
        { 
            using(var cnn=DbConnection)
            {
                var result = cnn.UpdateOnly<TuanOrderDTO>(() => new TuanOrderDTO { Tstate = state }, where: m => m.Id == id);
                return result > 0;
            }
        }
    }
}
